﻿using UnityEngine;
using System.Collections;
using UI;
using ProtoBuf.Message;
using System.Collections.Generic;
/// <summary>
/// 公会战网络管理器
/// </summary>
namespace Room
{
    public class RoomNetUnionFight : RoomNetBase
    {
        #region 移动包装类
        public class InnerMover
        {
            public long uuid;
            public Vector3 nextPos;
            public int state;

            public InnerMover() { }

            public InnerMover(long uuid, PointNew pos)
            {
                this.uuid = uuid;
                this.nextPos = new Vector3(pos.x, pos.y, pos.z);
            }
        }
        #endregion

        public RoomCharactorManager charactorManager;
        

        public NetUnionFightBattle netBattle;
        public NetUnionFightActor netActor;
        public NetUnionFightMonster netMonster;
        public NetUnionFightResource netResource;
        public NetUnionFightBaseCamp netCamp;
        public NetUnionFightChariot netChariot;
        public NetUnionFightChariotFactory netChariotFactory;
        public NetUnionFightGate netGate;
        public NetUnionFightRevivePoint netRevivePoint;
        public NetUnionFightTower netTower;
        public NetUnionFightGuard netGuard;
        public NetUnionFightAnnounce netAnnounce;

        public Queue<InnerMover> moveQueue = new Queue<InnerMover>();
        public List<NetUnionFightBase> netAction = new List<NetUnionFightBase>();

        public bool isRegistSocket = false;

        public float sendTime = 0.128f;
        public float forceSyncDis = 0;
        public float mainActorSpeed = 0f;

        public override void Enter()
        {
            NetAPI.CurrSceneId = (int)roomBase.GetServerType();
            RegistSocketHandler();
            enterTime = Time.unscaledTime;
            initState = 1;

            foreach (var netAc in netAction)
            {
                netAc.Enter();
            }

            SendCSCurrentPosition(null);
            DataMessageTool.AddHandler(DataMessage.NET_CONNECT_COMPLETE, SendCSCurrentPosition);

            var sendCount = Dict.DictDataManager.Instance.tableGameConfigureDao.currentData.UnionFightMoveHz;
            if(sendCount!=0)
            {
                sendTime = 1f / (float)sendCount;
            }

            forceSyncDis = (float)Dict.DictDataManager.Instance.tableGameConfigureDao.currentData.UnionFightForceSyncPositionRange;
        }

        public override void Pause()
        {
            foreach (var netAc in netAction)
            {
                netAc.Pause();
            }
        }

        public override void Resume()
        {
            foreach (var netAc in netAction)
            {
                netAc.Resume();
            }
        }

        public override void Init(RoomBase r)
        {
            roomBase = r;
            charactorManager = roomBase.charactorManager;

            netBattle = new NetUnionFightBattle((RoomUnionFight)r, charactorManager, this);
            netActor = new NetUnionFightActor((RoomUnionFight)r, charactorManager, this);
            netMonster = new NetUnionFightMonster((RoomUnionFight)r, charactorManager, this);
            netResource = new NetUnionFightResource((RoomUnionFight)r, charactorManager, this);
            netChariot = new NetUnionFightChariot((RoomUnionFight)r, charactorManager, this);
            netCamp = new NetUnionFightBaseCamp((RoomUnionFight)r, charactorManager, this);
            netTower = new NetUnionFightTower((RoomUnionFight)r, charactorManager, this);
            netAnnounce = new NetUnionFightAnnounce((RoomUnionFight)r, charactorManager, this);
            netChariotFactory = new NetUnionFightChariotFactory((RoomUnionFight)r, charactorManager, this);
            netRevivePoint = new NetUnionFightRevivePoint((RoomUnionFight)r, charactorManager, this);
            netGuard = new NetUnionFightGuard((RoomUnionFight)r, charactorManager, this);
            netGate = new NetUnionFightGate((RoomUnionFight)r, charactorManager, this);

            netAction.Clear();
            netAction.Add(netBattle);
            netAction.Add(netActor);
            netAction.Add(netMonster);
            netAction.Add(netResource);
            netAction.Add(netCamp);
            netAction.Add(netTower);
            netAction.Add(netChariotFactory);
            netAction.Add(netRevivePoint);
            netAction.Add(netGuard);
            netAction.Add(netBattle);
            netAction.Add(netGate);
            netAction.Add(netAnnounce);
        }

        public override void Tick()
        {
            foreach (var netAc in netAction)
            {
                netAc.Tick();
            }

            while (moveQueue.Count > 0)
            {
                SolveMoveActor(moveQueue.Dequeue());
            }

            if (initState == 2)
            {
                SolveSyncSelfToServer();
            }
            else if (initState == 1 && Time.unscaledTime - enterTime > 10)
            {
                SendCSUFInit();
                enterTime = Time.unscaledTime;
            }
        }

        public override void Leave()
        {
            UnRegistSocketHandler();

            foreach (var netAc in netAction)
            {
                netAc.Leave();
            }

            moveQueue.Clear();
            netAction.Clear();
            DataMessageTool.RemoveHandler(DataMessage.NET_CONNECT_COMPLETE, SendCSCurrentPosition);
        }


        #region 长连接协议
        public override void RegistSocketHandler()
        {
            NetAPI.RegistSocketHandler(OpDefine.SCCurrentPosition, SCCurrentPosition);

            NetAPI.RegistSocketHandler(OpDefine.SCUnionFightTransfer, SCUnionFightTransfer);//开始进入场景的协议
            NetAPI.RegistSocketHandler(OpDefine.SCUnionFightUpdateState, SCUnionFightUpdateState);//战场状态转换
            NetAPI.RegistSocketHandler(OpDefine.SCUnionFightResult, SCUnionFightResult);//战斗结果
            NetAPI.RegistSocketHandler(OpDefine.SCUFPlayer, SCUFPlayer);//刷新玩家
            NetAPI.RegistSocketHandler(OpDefine.SCUFCreep, SCUFCreep);//刷新野怪
            NetAPI.RegistSocketHandler(OpDefine.SCUFCaropt, SCUFCaropt);//刷新战车
            NetAPI.RegistSocketHandler(OpDefine.SCUFResourcePoint, SCUFResourcePoint);//刷新资源点
            NetAPI.RegistSocketHandler(OpDefine.SCUFRevivePoint, SCUFRevivePoint);//刷新复活点
            NetAPI.RegistSocketHandler(OpDefine.SCUFTower, SCUFTower);//刷新tower
            NetAPI.RegistSocketHandler(OpDefine.SCUFGate, SCUFGate);//刷新城门
            NetAPI.RegistSocketHandler(OpDefine.SCUFBaseCamp, SCUFBaseCamp);//刷新基地
            NetAPI.RegistSocketHandler(OpDefine.SCUFElementMove, SCUFElementMove);//统一移动
            NetAPI.RegistSocketHandler(OpDefine.SCUFElementBuffOn, SCUFElementBuffOn);//统一上buff
            NetAPI.RegistSocketHandler(OpDefine.SCUFElementBuffOff, SCUFElementBuffOff);//统一下buff
            NetAPI.RegistSocketHandler(OpDefine.SCUFElementTickExport, SCUFElementTickExport);//统一HPTick
            
            NetAPI.RegistSocketHandler(OpDefine.SCUFMonsterFightBegin, SCUFMonsterFightBegin);//野怪战斗开始
            NetAPI.RegistSocketHandler(OpDefine.SCUFMonsterFightEnd, SCUFMonsterFightEnd);//野怪战斗结束
            NetAPI.RegistSocketHandler(OpDefine.SCUFGuardFightBegin, SCUFGuardFightBegin);//守卫战斗开始
            NetAPI.RegistSocketHandler(OpDefine.SCUFGuardFightEnd, SCUFGuardFightEnd);//守卫战斗结束

            NetAPI.RegistSocketHandler(OpDefine.SCUFPlayerDead, SCUFPlayerDead);//玩家死亡
            NetAPI.RegistSocketHandler(OpDefine.SCUFMonsterDead, SCUFMonsterDead);//玩家死亡
            NetAPI.RegistSocketHandler(OpDefine.SCUFGuardDead, SCUFGuardDead);//玩家死亡

            NetAPI.RegistSocketHandler(OpDefine.SCUFPlayerCollect, SCUFPlayerCollect);//玩家开始采集
            NetAPI.RegistSocketHandler(OpDefine.SCUFPlayerCollectEnd, SCUFPlayerCollectEnd);//玩家结束采集
            NetAPI.RegistSocketHandler(OpDefine.SCUFPlayerCollectEndDetail, SCUFPlayerCollectEndDetail);//玩家自己采集结束
            NetAPI.RegistSocketHandler(OpDefine.SCUFPlayerUseItem, SCUFPlayerUseItem);//玩家使用道具
            NetAPI.RegistSocketHandler(OpDefine.SCUFPlayerUseItemDetail, SCUFPlayerUseItemDetail);
            NetAPI.RegistSocketHandler(OpDefine.SCUFPlayerAppear, SCUFPlayerAppear);//玩家出现
            NetAPI.RegistSocketHandler(OpDefine.SCUFPlayerDisappear, SCUFPlayerDisappear);//玩家消失
            NetAPI.RegistSocketHandler(OpDefine.SCUFCariotAttackGate, SCUFCariotAttackGate);//战车打城门
            NetAPI.RegistSocketHandler(OpDefine.SCUFCariotCrash, SCUFCariotCrash);//战车死亡
            NetAPI.RegistSocketHandler(OpDefine.SCUFCariotFactoryBuilding, SCUFCariotFactoryBuilding);//战车工厂工作
            NetAPI.RegistSocketHandler(OpDefine.SCUFCariotFactoryBuildComplete, SCUFCariotFactoryBuildComplete);//战车工厂造车完毕
            NetAPI.RegistSocketHandler(OpDefine.SCUFCariotFactoryOpen, SCUFCariotFactoryOpen);//战车工厂开启（野外的）
            NetAPI.RegistSocketHandler(OpDefine.SCUFCariotFactoryClose, SCUFCariotFactoryClose);//战车工厂关闭（野外的）
            NetAPI.RegistSocketHandler(OpDefine.SCUFCreepSpawn, SCUFCreepSpawn);//野怪出生
            NetAPI.RegistSocketHandler(OpDefine.SCUFResourcePointSpawn, SCUFResourcePointSpawn);//资源出生刷新
            NetAPI.RegistSocketHandler(OpDefine.SCUFTowerAttackCariot, SCUFTowerAttackCariot);//塔打车
            NetAPI.RegistSocketHandler(OpDefine.SCUFTowerAttackPlayer, SCUFTowerAttackPlayer);//塔打玩家
            NetAPI.RegistSocketHandler(OpDefine.SCUFTowerCrash, SCUFTowerCrash);//塔被毁（守卫死了）
            NetAPI.RegistSocketHandler(OpDefine.SCUFStrengthBuilding, SCUFStrengthBuilding);//建筑物强化
            NetAPI.RegistSocketHandler(OpDefine.SCUFGateCrash, SCUFGateCrash);//城门摧毁
            NetAPI.RegistSocketHandler(OpDefine.SCUFRevivePointOccupy, SCUFRevivePointOccupy);//出生点被占领
            NetAPI.RegistSocketHandler(OpDefine.SCUFPlayerRevive, SCUFPlayerRevive);//玩家复活


            NetAPI.RegistSocketHandler(OpDefine.SCUFPlayerFightBegin, SCUFPlayerFightBegin);//玩家进入战斗
            NetAPI.RegistSocketHandler(OpDefine.SCUFPlayerFightEnd, SCUFPlayerFightEnd);//玩家结束战斗
            NetAPI.RegistSocketHandler(OpDefine.SCUFPlayerFightEndDetail, SCUFPlayerFightEndDetail);//本人结束战斗
            NetAPI.RegistSocketHandler(OpDefine.SCUFPlayerUpResource, SCUFPlayerUpResource);//玩家上交资源

            NetAPI.RegistSocketHandler(OpDefine.SCUFBuildingRefresh, SCUFBuildingRefresh);
            NetAPI.RegistSocketHandler(OpDefine.SCUFCampResourceUpdate, SCUFCampResourceUpdate);
            NetAPI.RegistSocketHandler(OpDefine.SCUFRevivePointUpdate, SCUFRevivePointUpdate);
            NetAPI.RegistSocketHandler(OpDefine.SCUFPlayerBuyItemDetail, SCUFPlayerBuyItemDetail);

            NetAPI.RegistSocketHandler(OpDefine.SCUFPlayerBuyItem, SCUFPlayerBuyItem);

            NetAPI.RegistSocketHandler(OpDefine.SCUFShopList, SCUFShopList);
            NetAPI.RegistSocketHandler(OpDefine.SCUFStrengthBuildingInfo, SCUFStrengthBuildingInfo);//请求建筑物强化列表

            NetAPI.RegistSocketHandler(OpDefine.SCUFChatCache, (pack) =>
            {
                SCUFChatCache msg = pack as SCUFChatCache;
                Chat.ChatManager.Instance.ReceiUnionChat(msg.chatList);
            });
            
            NetAPI.RegistSocketHandler(OpDefine.SCUFPlayerMissionList, SCUFPlayerMissionList);//任务
            NetAPI.RegistSocketHandler(OpDefine.SCUFUnionMissionList, SCUFUnionMissionList);
            NetAPI.RegistSocketHandler(OpDefine.SCUFMissionPush, SCUFMissionPush);

            NetAPI.RegistSocketHandler(OpDefine.SCUFTotemCreate, SCUFTotemCreate);
            NetAPI.RegistSocketHandler(OpDefine.SCUFTotemDestroy, SCUFTotemDestroy);

            NetAPI.RegistSocketHandler(OpDefine.SCUFMainPlayerSpeedChange, SCUFMainPlayerSpeedChange);
            NetAPI.RegistSocketHandler(OpDefine.SCUFFightRecord, SCUFFightRecord);//战斗记录
            NetAPI.RegistSocketHandler(OpDefine.SCUFFightRecordReplay, SCUFFightRecordReplay);//观看记录
            NetAPI.RegistSocketHandler(OpDefine.SCUFLeaderFocus, SCUFLeaderFocus);//集结点显示
            NetAPI.RegistSocketHandler(OpDefine.SCUFFocusPointInfo, SCUFFocusPointInfo);//集结点消失  
            NetAPI.RegistSocketHandler(OpDefine.SCUFPlayerCcmpleteAchieve, SCUFPlayerCcmpleteAchieve);//连杀特效
            NetAPI.RegistSocketHandler(OpDefine.SCUFOnHook, SCUFOnHook);
            NetAPI.RegistSocketHandler(OpDefine.SCUFEndTransfer, SCUFEndTransfer);
            NetAPI.RegistSocketHandler(OpDefine.SCUFBeginTransfer, SCUFBeginTransfer);
            NetAPI.RegistSocketHandler(OpDefine.SCUFKickPlayer, SCUFKickPlayer);
            NetAPI.RegistSocketHandler(OpDefine.SCUFCariotFactory, SCUFCariotFactory);
            NetAPI.RegistSocketHandler(OpDefine.SCUFTowerRecovery, SCUFTowerRecovery);
            NetAPI.RegistSocketHandler(OpDefine.SCUFTalk, SCUFTalk);//公会喊话
            NetAPI.RegistSocketHandler(OpDefine.SCPublicMessage, SCPublicMessage);//跑马灯
            isRegistSocket = true;
        }

        public override void UnRegistSocketHandler()
        {
            if (isRegistSocket)
            {
                NetAPI.UnregisterSocketHandler(OpDefine.SCCurrentPosition, SCCurrentPosition);

                NetAPI.UnregisterSocketHandler(OpDefine.SCUnionFightTransfer, SCUnionFightTransfer);//开始进入场景的协议
                NetAPI.UnregisterSocketHandler(OpDefine.SCUnionFightUpdateState, SCUnionFightUpdateState);//战场状态转换
                NetAPI.UnregisterSocketHandler(OpDefine.SCUnionFightResult, SCUnionFightResult);//战斗结果
                NetAPI.UnregisterSocketHandler(OpDefine.SCUFPlayer, SCUFPlayer);//刷新玩家
                NetAPI.UnregisterSocketHandler(OpDefine.SCUFCreep, SCUFCreep);//刷新野怪
                NetAPI.UnregisterSocketHandler(OpDefine.SCUFCaropt, SCUFCaropt);//刷新战车
                NetAPI.UnregisterSocketHandler(OpDefine.SCUFResourcePoint, SCUFResourcePoint);//刷新资源点
                NetAPI.UnregisterSocketHandler(OpDefine.SCUFRevivePoint, SCUFRevivePoint);//刷新复活点
                NetAPI.UnregisterSocketHandler(OpDefine.SCUFTower, SCUFTower);//刷新tower
                NetAPI.UnregisterSocketHandler(OpDefine.SCUFGate, SCUFGate);//刷新城门
                NetAPI.UnregisterSocketHandler(OpDefine.SCUFBaseCamp, SCUFBaseCamp);//刷新基地
                NetAPI.UnregisterSocketHandler(OpDefine.SCUFElementMove, SCUFElementMove);//统一移动
                NetAPI.UnregisterSocketHandler(OpDefine.SCUFElementBuffOn, SCUFElementBuffOn);//统一上buff
                NetAPI.UnregisterSocketHandler(OpDefine.SCUFElementBuffOff, SCUFElementBuffOff);//统一下buff
                NetAPI.UnregisterSocketHandler(OpDefine.SCUFElementTickExport, SCUFElementTickExport);//统一HPTick
                

                NetAPI.UnregisterSocketHandler(OpDefine.SCUFMonsterFightBegin, SCUFMonsterFightBegin);//野怪战斗开始
                NetAPI.UnregisterSocketHandler(OpDefine.SCUFMonsterFightEnd, SCUFMonsterFightEnd);//野怪战斗结束
                NetAPI.UnregisterSocketHandler(OpDefine.SCUFGuardFightBegin, SCUFGuardFightBegin);//守卫战斗开始
                NetAPI.UnregisterSocketHandler(OpDefine.SCUFGuardFightEnd, SCUFGuardFightEnd);//守卫战斗结束

                NetAPI.UnregisterSocketHandler(OpDefine.SCUFPlayerDead, SCUFPlayerDead);//玩家死亡

                NetAPI.UnregisterSocketHandler(OpDefine.SCUFMonsterDead, SCUFMonsterDead);//玩家死亡
                NetAPI.UnregisterSocketHandler(OpDefine.SCUFGuardDead, SCUFGuardDead);//玩家死亡

                NetAPI.UnregisterSocketHandler(OpDefine.SCUFPlayerFightBegin, SCUFPlayerFightBegin);//玩家进入战斗
                NetAPI.UnregisterSocketHandler(OpDefine.SCUFPlayerFightEnd, SCUFPlayerFightEnd);//玩家结束战斗
                NetAPI.UnregisterSocketHandler(OpDefine.SCUFPlayerFightEndDetail, SCUFPlayerFightEndDetail);//本人结束战斗


                NetAPI.UnregisterSocketHandler(OpDefine.SCUFPlayerCollect, SCUFPlayerCollect);//玩家开始采集
                NetAPI.UnregisterSocketHandler(OpDefine.SCUFPlayerCollectEnd, SCUFPlayerCollectEnd);//玩家结束采集
                NetAPI.UnregisterSocketHandler(OpDefine.SCUFPlayerCollectEndDetail, SCUFPlayerCollectEndDetail);//玩家自己采集结束
                NetAPI.UnregisterSocketHandler(OpDefine.SCUFPlayerUseItem, SCUFPlayerUseItem);//玩家使用道具
                NetAPI.UnregisterSocketHandler(OpDefine.SCUFPlayerUseItemDetail, SCUFPlayerUseItemDetail);
                NetAPI.UnregisterSocketHandler(OpDefine.SCUFPlayerAppear, SCUFPlayerAppear);//玩家出现
                NetAPI.UnregisterSocketHandler(OpDefine.SCUFPlayerDisappear, SCUFPlayerDisappear);//玩家消失
                NetAPI.UnregisterSocketHandler(OpDefine.SCUFCariotAttackGate, SCUFCariotAttackGate);//战车打城门
                NetAPI.UnregisterSocketHandler(OpDefine.SCUFCariotCrash, SCUFCariotCrash);//战车死亡
                NetAPI.UnregisterSocketHandler(OpDefine.SCUFCariotFactoryBuilding, SCUFCariotFactoryBuilding);//战车工厂工作
                NetAPI.UnregisterSocketHandler(OpDefine.SCUFCariotFactoryBuildComplete, SCUFCariotFactoryBuildComplete);//战车工厂造车完毕
                NetAPI.UnregisterSocketHandler(OpDefine.SCUFCariotFactoryOpen, SCUFCariotFactoryOpen);//战车工厂开启（野外的）
                NetAPI.UnregisterSocketHandler(OpDefine.SCUFCariotFactoryClose, SCUFCariotFactoryClose);//战车工厂关闭（野外的）
                NetAPI.UnregisterSocketHandler(OpDefine.SCUFCreepSpawn, SCUFCreepSpawn);//野怪出生
                NetAPI.UnregisterSocketHandler(OpDefine.SCUFResourcePointSpawn, SCUFResourcePointSpawn);//资源出生刷新
                NetAPI.UnregisterSocketHandler(OpDefine.SCUFTowerAttackCariot, SCUFTowerAttackCariot);//塔打车
                NetAPI.UnregisterSocketHandler(OpDefine.SCUFTowerAttackPlayer, SCUFTowerAttackPlayer);//塔打玩家
                NetAPI.UnregisterSocketHandler(OpDefine.SCUFTowerCrash, SCUFTowerCrash);//塔被毁（守卫死了）
                NetAPI.UnregisterSocketHandler(OpDefine.SCUFStrengthBuilding, SCUFStrengthBuilding);//建筑物强化
                NetAPI.UnregisterSocketHandler(OpDefine.SCUFGateCrash, SCUFGateCrash);//城门摧毁
                NetAPI.UnregisterSocketHandler(OpDefine.SCUFRevivePointOccupy, SCUFRevivePointOccupy);//出生点被占领
                NetAPI.UnregisterSocketHandler(OpDefine.SCUFPlayerRevive, SCUFPlayerRevive);//玩家复活
                NetAPI.UnregisterSocketHandler(OpDefine.SCUFPlayerUpResource, SCUFPlayerUpResource);//玩家上交资源

                NetAPI.UnregisterSocketHandler(OpDefine.SCUFBuildingRefresh, SCUFBuildingRefresh);
                NetAPI.UnregisterSocketHandler(OpDefine.SCUFCampResourceUpdate, SCUFCampResourceUpdate);
                NetAPI.UnregisterSocketHandler(OpDefine.SCUFRevivePointUpdate, SCUFRevivePointUpdate);
                NetAPI.UnregisterSocketHandler(OpDefine.SCUFPlayerBuyItemDetail, SCUFPlayerBuyItemDetail);
                NetAPI.UnregisterSocketHandler(OpDefine.SCUFStrengthBuildingInfo, SCUFStrengthBuildingInfo);//请求建筑物强化列表
                NetAPI.UnregisterSocketHandler(OpDefine.SCUFPlayerBuyItem, SCUFPlayerBuyItem);
                NetAPI.UnregisterSocketHandler(OpDefine.SCUFPlayerMissionList, SCUFPlayerMissionList);//任务
                NetAPI.UnregisterSocketHandler(OpDefine.SCUFUnionMissionList, SCUFUnionMissionList);
                NetAPI.UnregisterSocketHandler(OpDefine.SCUFMissionPush, SCUFMissionPush);
                NetAPI.UnregisterSocketHandler(OpDefine.SCUFShopList, SCUFShopList);
                NetAPI.UnregisterSocketHandler(OpDefine.SCUFTotemCreate, SCUFTotemCreate);
                NetAPI.UnregisterSocketHandler(OpDefine.SCUFTotemDestroy, SCUFTotemDestroy);

                NetAPI.UnregisterSocketHandler(OpDefine.SCUFMainPlayerSpeedChange, SCUFMainPlayerSpeedChange);
                NetAPI.UnregisterSocketHandler(OpDefine.SCUFFightRecord, SCUFFightRecord);//战斗记录
                NetAPI.RegistSocketHandler(OpDefine.SCUFFightRecordReplay, SCUFFightRecordReplay);//观看记录
                NetAPI.UnregisterSocketHandler(OpDefine.SCUFLeaderFocus, SCUFLeaderFocus);//集结点
                NetAPI.UnregisterSocketHandler(OpDefine.SCUFFocusPointInfo, SCUFFocusPointInfo);//集结点消失
                NetAPI.UnregisterSocketHandler(OpDefine.SCUFPlayerCcmpleteAchieve, SCUFPlayerCcmpleteAchieve);//连杀特效

                NetAPI.UnregisterSocketHandler(OpDefine.SCUFOnHook, SCUFOnHook);
                NetAPI.UnregisterSocketHandler(OpDefine.SCUFEndTransfer, SCUFEndTransfer);
                NetAPI.UnregisterSocketHandler(OpDefine.SCUFBeginTransfer, SCUFBeginTransfer);

                NetAPI.UnregisterSocketHandler(OpDefine.SCUFKickPlayer, SCUFKickPlayer);
                NetAPI.UnregisterSocketHandler(OpDefine.SCUFCariotFactory, SCUFCariotFactory);
                NetAPI.UnregisterSocketHandler(OpDefine.SCUFTowerRecovery, SCUFTowerRecovery);
                NetAPI.UnregisterSocketHandler(OpDefine.SCUFTalk, SCUFTalk);//公会喊话
                NetAPI.UnregisterSocketHandler(OpDefine.SCPublicMessage, SCPublicMessage);//跑马灯
                isRegistSocket = false;
            }
        }
        #endregion

        #region CS

        public override void SendCSCurrentPosition(object sender)
        {
            var msg = new CSCurrentPosition();
            Debug.Log("<color=yellow>UnintFight CSCurrentPosition </color>");
            msg.showArround = 1;
            NetAPI.SendSocket(OpDefine.CSCurrentPosition, msg);
        }

        /// <summary>
        /// 请求初始化信息
        /// </summary>
        public void SendCSUFInit()
        {
            var msg = new CSUFInit();
            NetAPI.SendSocket(OpDefine.CSUFInit, msg);
            Debug.Log("<color=blue>[send] CSUFInit </color>");
        }



        /// <summary>
        /// 玩家采集资源
        /// </summary>
        /// <param name="uuid"></param>
        public void SendCSUFPlayerCollect(long uuid)
        {
            var msg = new CSUFPlayerCollect();
            msg.resGuid = uuid;
            NetAPI.SendSocket(OpDefine.CSUFPlayerCollect, msg);
            Debug.Log("<color=blue>[send] SendCSUFPlayerCollect </color>");
        }
        /// <summary>
        /// 玩家上交资源
        /// </summary>
        public void SendCSUFPlayerUpResource(string npcId)
        {
            var msg = new CSUFPlayerUpResource();
            msg.npcId = npcId;
            NetAPI.SendSocket(OpDefine.CSUFPlayerUpResource, msg);
            Debug.Log("<color=blue>[send] CSUFPlayerUpResource </color>");
        }

        /// <summary>
        /// 移动确认
        /// </summary>
        public void SendCSMoveConfirm()
        {
            NetAPI.SendSocket(OpDefine.CSMoveConfirm, new CSMoveConfirm());
        }


        /// <summary>
        /// 玩家购买商品
        /// </summary>
        /// <param name="shopItemId"></param>
        public void SendCSUFPlayerBuyItem(string shopItemId,string npcId)
        {
            var msg = new CSUFPlayerBuyItem();
            msg.shopItemId = shopItemId;
            msg.npcId = npcId;
            NetAPI.SendSocket(OpDefine.CSUFPlayerBuyItem, msg);
        }

        /// <summary>
        /// 使用物品的协议
        /// </summary>
        /// <param name="itemId"></param>
        public void SendCSUFPlayerUseItem(string itemId)
        {
            var msg = new CSUFPlayerUseItem();
            msg.itemId = itemId;
            NetAPI.SendSocket(OpDefine.CSUFPlayerUseItem, msg);
            Debug.Log("<color=yellow>[INFO] SendCSUFPlayerUseItem </color> itemId[" + itemId + "]");
        }

        /// <summary>
        /// 请求商品List
        /// </summary>
        public void SendCSUFShopList(string npcId)
        {
            var msg = new CSUFShopList();
            msg.npcId = npcId;
            NetAPI.SendSocket(OpDefine.CSUFShopList, msg);
        }

        /// <summary>
        /// 统一的刷新
        /// </summary>
        /// <param name="uuid"></param>
        public void SendCSUFRefreshElement(long uuid)
        {
            var msg = new CSUFRefreshElement();
            msg.guid = uuid;
            NetAPI.SendSocket(OpDefine.CSUFRefreshElement, msg);
            Debug.Log("<color=yellow>[INFO] SendCSUFRefreshElement </color> uuid["+uuid+"]");
        }


        /// <summary>
        /// 请求野外工厂开启
        /// </summary>
        /// <param name="uuid"></param>
        public void SendCSUFFieldCariotFactoryOpen(long uuid,string npcId)
        {
            var msg = new CSUFFieldCariotFactoryOpen();
            msg.factoryGuid = uuid;
            msg.npcId = npcId;
            NetAPI.SendSocket(OpDefine.CSUFFieldCariotFactoryOpen, msg);
            Debug.Log("<color=yellow>[INFO] CSUFFieldCariotFactoryOpen </color> uuid[" + uuid + "]");
        }

        public void SendCSUFStrengthBuildingInfo(string npcId)
        {
            var msg = new CSUFStrengthBuildingInfo();
            msg.npcId = npcId;
            NetAPI.SendSocket(OpDefine.CSUFStrengthBuildingInfo, msg);
        }

        /// <summary>
        /// 建筑物强化
        /// </summary>
        public void SendCSUFStrengthBuilding(int type,string npcId)
        {
            var msg = new CSUFStrengthBuilding();
            msg.type = type ;
            msg.npcId = npcId;
            NetAPI.SendSocket(OpDefine.CSUFStrengthBuilding, msg);
            Debug.Log("<color=yellow>[INFO] SendCSUFStrengthBuilding </color> type[" + type + "]");
        }
        
        /// <summary>
        /// 请求攻击
        /// </summary>
        /// <param name="uuid"></param>
        public void SendCSUFPlayerAskFight(long uuid)
        {
            var msg = new CSUFPlayerAskFight();
            msg.targetGuid = uuid;
            NetAPI.SendSocket(OpDefine.CSUFPlayerAskFight, msg);
            Debug.Log("<color=yellow>[INFO] SendCSUFPlayerAskFight </color> uuid[" + uuid + "]");
        }
        //请求任务列表
        public void SendCSUFPlayerMissionList()
        {
            NetAPI.SendSocket(OpDefine.CSUFPlayerMissionList, new CSUFPlayerMissionList());
        }

        public void SendCSUFUnionMissionList()
        {
            NetAPI.SendSocket(OpDefine.CSUFUnionMissionList, new CSUFUnionMissionList());
        }

        //战斗记录
        public void SendCSUFFightRecord()
        {
            NetAPI.SendSocket(OpDefine.CSUFFightRecord, new CSUFFightRecord());
        }

        public void SendCSUFFightRecordReplay(long fightId)
        {
            var msg = new CSUFFightRecordReplay();
            msg.fightId = fightId;
            NetAPI.SendSocket(OpDefine.CSUFFightRecordReplay, msg);
        }
        //后台切回战斗结算界面
        public void SendCSUFFightResult()
        {
            NetAPI.SendSocket(OpDefine.CSUFFightResult, new CSUFFightResult());
        }

        //集结点
        public void SendCSUFLeaderFocus(Vector3 pos)
        {
            var msg = new CSUFLeaderFocus();
            msg.pos = new PointNew();
            msg.pos.x = pos.x; 
            msg.pos.y = pos.y; 
            msg.pos.z = pos.z;
            NetAPI.SendSocket(OpDefine.CSUFLeaderFocus, msg);
        }

        //公会喊话
        public void SendCSUFTalk(string content)
        {
            var msg = new CSUFTalk();
            msg.content = content;
            NetAPI.SendSocket(OpDefine.CSUFTalk, msg);
        }
        /// <summary>
        /// 挂机
        /// </summary>
        /// <param name="on"></param>
        public void SendCSUFOnHook(bool on)
        {
            var msg = new CSUFOnHook();
            msg.onHook = on ? 1 : 0;
            NetAPI.SendSocket(OpDefine.CSUFOnHook, msg);
            Debug.Log("<color=yellow>[INFO] SendCSUFOnHook </color> ");
        }

        /// <summary>
        /// 回基地
        /// </summary>
        public void SendCSBeginTransfer(Vector3 pos,string transferId)
        {
            var msg = new CSUFBeginTransfer();
            msg.target = new PointNew();
            msg.target.x = pos.x;
            msg.target.y = pos.y;
            msg.target.z = pos.z;
            msg.transferId = transferId;
            NetAPI.SendSocket(OpDefine.CSUFBeginTransfer, msg);
            Debug.Log("<color=yellow>[INFO] SendCSAskTransfer </color> ");
        }        
		#endregion

        #region SC

        protected override void SCCurrentPosition(object obj)
        {
            Debug.Log("<color=purple>[union fight]recv SCCurrentPosition</color>");
        }

        //开始进入场景的协议
        void SCUnionFightTransfer(object obj)
        {
            var msg = (SCUnionFightTransfer)obj;

            netBattle.UnionFightEnter(msg);
            var self = charactorManager.GetSelfCharactor();
            if (self != null)
            {
                var tr = self.transform;
                tr.localPosition = new Vector3(msg.playerPos.x, msg.playerPos.y, msg.playerPos.z);
                roomBase.OnMainCharactorLoaded(tr);
                initState = 2;
            }

            NetAPI.SendSocket(OpDefine.CSUFChatCache, new CSUFChatCache());

            Debug.Log("<color=purple>[union fight]recv SCUnionFightTransfer</color>");
        }
        //战场状态转换
        void SCUnionFightUpdateState(object obj)
        {
            netBattle.UnionFightState((SCUnionFightUpdateState)obj);
            Debug.Log("<color=purple>[union fight]recv SCUnionFightUpdateState</color>");
        }

        //战斗结果
        void SCUnionFightResult(object obj)
        {
            netBattle.UnionFightResult((SCUnionFightResult)obj);
            Debug.Log("<color=purple>[union fight]recv SCUnionFightResult</color>");
        }

        //刷新玩家
        void SCUFPlayer(object obj)
        {
            netActor.ActorRefresh((SCUFPlayer)obj);
            Debug.Log("<color=purple>[union fight]recv SCUFPlayer</color>");
        }
        //刷新野怪
        void SCUFCreep(object obj)
        {
            netMonster.MonsterRefresh((SCUFCreep)obj);
            Debug.Log("<color=purple>[union fight]recv SCUFCreep</color>");
        }
        //刷新战车
        void SCUFCaropt(object obj)
        {
            netChariot.ChariotRefresh((SCUFCaropt)obj);
            Debug.Log("<color=purple>[union fight]recv SCUFCaropt</color>");
        }

        //刷新资源点
        void SCUFResourcePoint(object obj)
        {
            netResource.ResourceRefresh((SCUFResourcePoint)obj);
            Debug.Log("<color=purple>[union fight]recv SCUFResourcePoint</color>");
        }

        //刷新复活点
        void SCUFRevivePoint(object obj)
        {
            netRevivePoint.RevivePointRefresh((SCUFRevivePoint)obj);
            Debug.Log("<color=purple>[union fight]recv SCUFRevivePoint</color>");
        }

        //刷tower
        void SCUFTower(object obj)
        {
            netTower.TowerRefresh((SCUFTower)obj);
            Debug.Log("<color=purple>[union fight]recv SCUFTower</color>");
        }

        //刷门
        void SCUFGate(object obj)
        {
            netGate.GateRefresh((SCUFGate)obj);
            Debug.Log("<color=purple>[union fight]recv SCUFGate</color>");
        }

        //刷新基地
        void SCUFBaseCamp(object obj)
        {
            netCamp.BaseCampRefresh((SCUFBaseCamp)obj);
            Debug.Log("<color=purple>[union fight]recv SCUFBaseCamp</color>");
        }



        /// <summary>
        /// 统一的移动
        /// </summary>
        /// <param name="obj"></param>
        void SCUFElementMove(object obj)
        {
            SolveCommonMove((SCUFElementMove)obj);
            Debug.Log("<color=purple>[INFO]recv SCUFElementMove</color>");
        }

        /// <summary>
        /// 统一上buff
        /// </summary>
        /// <param name="obj"></param>
        void SCUFElementBuffOn(object obj)
        {
            netBattle.LoadBuff((SCUFElementBuffOn)obj);
            Debug.Log("<color=purple>[INFO]recv SCUFElementBuffOn</color>");
        }

        /// <summary>
        /// 统一的下BUFF
        /// </summary>
        /// <param name="obj"></param>
        void SCUFElementBuffOff(object obj)
        {
            netBattle.UnloadBuff((SCUFElementBuffOff)obj);
            Debug.Log("<color=purple>[INFO]recv SCUFElementBuffOff</color>");
        }

        /// <summary>
        /// 统一的buff tick
        /// </summary>
        /// <param name="obj"></param>
        void SCUFElementTickExport(object obj)
        {
            netBattle.TickHp((SCUFElementTickExport)obj);
            Debug.Log("<color=purple>[INFO]recv SCUFElementTickExport</color>");
        }

        ///// <summary>
        ///// 玩家战斗开始
        ///// </summary>
        ///// <param name="obj"></param>
        //void SCUFFightBegin(object obj)
        //{
        //    netActor.ActorFightStart((SCUFFightBegin)obj);
        //    Debug.Log("<color=cyan>[INFO]recv SCUFFightBegin</color>");
        //}

        ///// <summary>
        ///// 玩家战斗结束
        ///// </summary>
        ///// <param name="obj"></param>
        //void SCUFFightEnd(object obj)
        //{
        //    netActor.ActorFightEnd((SCUFFightEnd)obj);
        //    Debug.Log("<color=cyan>[INFO]recv SCUFFightEnd</color>");
        //}


        /// <summary>
        /// 野怪战斗开始
        /// </summary>
        /// <param name="obj"></param>
        void SCUFMonsterFightBegin(object obj)
        {
            netMonster.MonsterFightBegin((SCUFMonsterFightBegin)obj);
            Debug.Log("<color=blue>[INFO]recv SCUFMonsterFightBegin</color>");
        }


        /// <summary>
        /// 野怪战斗结束
        /// </summary>
        /// <param name="obj"></param>
        void SCUFMonsterFightEnd(object obj)
        {
            netMonster.MonsterFightEnd((SCUFMonsterFightEnd)obj);
            Debug.Log("<color=blue>[INFO]recv SCUFMonsterFightEnd</color>");
        }

        /// <summary>
        /// 守卫战斗开始
        /// </summary>
        /// <param name="obj"></param>
        void SCUFGuardFightBegin(object obj)
        {
            netGuard.GuardFightBegin((SCUFGuardFightBegin)obj);
            Debug.Log("<color=green>[INFO]recv SCUFGuardFightBegin</color>");
        }

        /// <summary>
        /// 守卫战斗结束
        /// </summary>
        /// <param name="obj"></param>
        void SCUFGuardFightEnd(object obj)
        {
            netGuard.GuardFightEnd((SCUFGuardFightEnd)obj);
            Debug.Log("<color=green>[INFO]recv SCUFGuardFightEnd</color>");
        }
        //玩家死亡
        void SCUFPlayerDead(object obj)
        {
            netActor.ActorDead((SCUFPlayerDead)obj);
            Debug.Log("<color=purple>[union fight]recv SCUFPlayerDead</color>");
        }

        void SCUFGuardDead(object obj)
        {
            netGuard.GuardDead((SCUFGuardDead)obj);
            Debug.Log("<color=purple>[union fight]recv SCUFGuardDead</color>");
        }

        void SCUFPlayerFightBegin(object obj)
        {
            netActor.ActorFightStart((SCUFPlayerFightBegin)obj);
            Debug.Log("<color=purple>[union fight]recv SCUFPlayerFightBegin</color>");
        }

        void SCUFPlayerFightEnd(object obj)
        {
            netActor.ActorFightEnd((SCUFPlayerFightEnd)obj);
            Debug.Log("<color=purple>[union fight]recv SCUFPlayerFightEnd</color>");
        }

        void SCUFPlayerFightEndDetail(object obj)
        {
            netActor.ActorFightEndDetail((SCUFPlayerFightEndDetail)obj);
            Debug.Log("<color=purple>[union fight]recv SCUFPlayerFightEndDetail</color>");
        }

        void SCUFMonsterDead(object obj)
        {
            netMonster.MonsterDead((SCUFMonsterDead)obj);
            Debug.Log("<color=purple>[union fight]recv SCUFMonsterDead</color>");
        }

        //玩家开始采集
        void SCUFPlayerCollect(object obj)
        {
            netActor.ActorStartCollect((SCUFPlayerCollect)obj);
            Debug.Log("<color=purple>[union fight]recv SCUFPlayerCollect</color>");
        }

        //玩家结束采集
        void SCUFPlayerCollectEnd(object obj)
        {
            netActor.ActorEndCollect((SCUFPlayerCollectEnd)obj);
            Debug.Log("<color=purple>[union fight]recv SCUFPlayerCollectEnd</color>");
        }

        /// <summary>
        /// 自己的收集结束
        /// </summary>
        /// <param name="obj"></param>
        void SCUFPlayerCollectEndDetail(object obj)
        {
            netActor.ActorEndCollectDetail((SCUFPlayerCollectEndDetail)obj);
            Debug.Log("<color=purple>[union fight]recv SCUFPlayerCollectEndDetail</color>");
        }

        //玩家使用道具
        void SCUFPlayerUseItem(object obj)
        {
            netActor.ActorUseItem((SCUFPlayerUseItem)obj);
            Debug.Log("<color=purple>[union fight]recv SCUFPlayerUseItem</color>");
        }

        /// <summary>
        /// 自己使用物品
        /// </summary>
        /// <param name="obj"></param>
        void SCUFPlayerUseItemDetail(object obj)
        {
            netActor.ActorUseItemDetail((SCUFPlayerUseItemDetail)obj);
            Debug.Log("<color=purple>[union fight]recv SCUFPlayerUseItemDetail</color>");
        }

        //玩家出现
        void SCUFPlayerAppear(object obj)
        {
            netActor.ActorAppear((SCUFPlayerAppear)obj);
            Debug.Log("<color=purple>[union fight]recv SCUFPlayerAppear</color>");
        }

        //玩家消失
        void SCUFPlayerDisappear(object obj)
        {
            netActor.ActorDisappear((SCUFPlayerDisappear)obj);
            Debug.Log("<color=purple>[union fight]recv SCUFPlayerDisappear</color>");
        }

        //战车打城门
        void SCUFCariotAttackGate(object obj)
        {
            netChariot.ChariotAttackGate((SCUFCariotAttackGate)obj);
            Debug.Log("<color=purple>[union fight]recv SCUFCariotAttackGate</color>");
        }

        //战车死亡
        void SCUFCariotCrash(object obj)
        {
            netChariot.ChariotDead((SCUFCariotCrash)obj);
            Debug.Log("<color=purple>[union fight]recv SCUFCariotCrash</color>");
        }
        //战车工厂工作
        void SCUFCariotFactoryBuilding(object obj)
        {
            netChariotFactory.ChariotFactoryWorking((SCUFCariotFactoryBuilding)obj);
            Debug.Log("<color=purple>[union fight]recv SCUFCariotFactoryBuilding</color>");
        }
        //战车工厂造车完毕
        void SCUFCariotFactoryBuildComplete(object obj)
        {
            netChariotFactory.ChariotFactoryBuildComplete((SCUFCariotFactoryBuildComplete)obj);
            Debug.Log("<color=purple>[union fight]recv SCUFCariotFactoryBuildComplete</color>");
        }
        //战车工厂开启（野外的）
        void SCUFCariotFactoryOpen(object obj)
        {
            netChariotFactory.FieldChariotFactoryOpen((SCUFCariotFactoryOpen)obj);
            Debug.Log("<color=purple>[union fight]recv SCUFCariotFactoryOpen</color>");
        }
        //战车工厂关闭（野外的）
        void SCUFCariotFactoryClose(object obj)
        {
            netChariotFactory.FieldChariotFactoryClose((SCUFCariotFactoryClose)obj);
            Debug.Log("<color=purple>[union fight]recv SCUFCariotFactoryClose</color>");
        }

        //野怪出生
        void SCUFCreepSpawn(object obj)
        {
            netMonster.MonsterBorn((SCUFCreepSpawn)obj);
            Debug.Log("<color=purple>[union fight]recv SCUFCreepSpawn</color>");
        }

        //资源出生刷新
        void SCUFResourcePointSpawn(object obj)
        {
            netResource.ResourceSpawn((SCUFResourcePointSpawn)obj);
            Debug.Log("<color=purple>[union fight]recv SCUFResourcePointSpawn</color>");
        }

        //塔打车
        void SCUFTowerAttackCariot(object obj)
        {
            netTower.TowerAttackCariot((SCUFTowerAttackCariot)obj);
            Debug.Log("<color=purple>[union fight]recv SCUFTowerAttackCariot</color>");
        }
        //塔打玩家
        void SCUFTowerAttackPlayer(object obj)
        {
            netTower.TowerAttackActor((SCUFTowerAttackPlayer)obj);
            Debug.Log("<color=purple>[union fight]recv SCUFTowerAttackPlayer</color>");
        }
        //塔被毁（守卫死了）
        void SCUFTowerCrash(object obj)
        {
            netTower.TowerDestroy((SCUFTowerCrash)obj);
            Debug.Log("<color=purple>[union fight]recv SCUFTowerCrash</color>");
        }

        //强化列表信息
        void SCUFStrengthBuildingInfo(object obj)
        {
            netBattle.StrenthenBuildingInfo((SCUFStrengthBuildingInfo)obj);
            Debug.Log("<color=purple>[union fight]recv SCUFStrengthBuildingInfo</color>");
        }
        

        //建筑物强化
        void SCUFStrengthBuilding(object obj)
        {
            netActor.ActorStrengthenBuilding((SCUFStrengthBuilding)obj);
            Debug.Log("<color=purple>[union fight]recv SCUFStrengthBuilding</color>");
        }

        //城门摧毁
        void SCUFGateCrash(object obj)
        {
            netGate.GateDestroy((SCUFGateCrash)obj);
            Debug.Log("<color=purple>[union fight]recv SCUFGateCrash</color>");
        }

        //出生点被占领
        void SCUFRevivePointOccupy(object obj)
        {
            netRevivePoint.RevivePointOccupy((SCUFRevivePointOccupy)obj);
            Debug.Log("<color=purple>[union fight]recv SCUFRevivePointOccupy</color>");
        }

        /// <summary>
        /// 玩家复活
        /// </summary>
        /// <param name="obj"></param>
        void SCUFPlayerRevive(object obj)
        {
            netActor.ActorRevive((SCUFPlayerRevive)obj);
            Debug.Log("<color=purple>[union fight]recv SCUFPlayerRevive</color>");
        }

        /// <summary>
        /// 刷新建筑物
        /// </summary>
        /// <param name="obj"></param>
        void SCUFBuildingRefresh(object obj)
        {
            netBattle.BattleBuildingRefresh((SCUFBuildingRefresh)obj);
            Debug.Log("<color=purple>[union fight]recv SCUFBuildingRefresh</color>");
        }

        /// <summary>
        /// 阵营的总资源数
        /// </summary>
        /// <param name="obj"></param>
        void SCUFCampResourceUpdate(object obj)
        {
            var msg = (SCUFCampResourceUpdate)obj;
            netBattle.UnionResourceRefresh(msg);
            Debug.Log("<color=purple>[union fight]recv SCUFCampResourceUpdate</color>");
        }

        //复活点刷新
        void SCUFRevivePointUpdate(object msg)
        {
            netRevivePoint.RevivePointUpdate((SCUFRevivePointUpdate)msg);
            Debug.Log("<color=purple>[union fight]recv SCUFRevivePointUpdate</color>");
        }

        /// <summary>
        /// 自己买东西详细推送
        /// </summary>
        /// <param name="obj"></param>
        void SCUFPlayerBuyItemDetail(object obj)
        {
            netActor.ActorBuyItemDetail((SCUFPlayerBuyItemDetail)obj);
            Debug.Log("<color=purple>[union fight]recv SCUFPlayerBuyItemDetail</color>");
        }

        /// <summary>
        /// 玩家买道具     暂时无用
        /// </summary>
        /// <param name="obj"></param>
        void SCUFPlayerBuyItem(object obj)
        {
            netActor.ActorBuyItem((SCUFPlayerBuyItem)obj);
            Debug.Log("<color=purple>[union fight]recv SCUFPlayerBuyItem</color>");
        }

        void SCUFPlayerUpResource(object obj)
        {
            netActor.ActorUpResource((SCUFPlayerUpResource)obj);
            Debug.Log("<color=purple>[union fight]recv SCUFPlayerUpResource</color>");
        }

    /// <summary>
    /// 商品列表
    /// </summary>
    /// <param name="obj"></param>
        void SCUFShopList(object obj)
        {
            netBattle.BattleProductList((SCUFShopList)obj);
            Debug.Log("[Union Inner Shop] SCUFShopList");
        }

        /// <summary>
        /// 图腾创建
        /// </summary>
        /// <param name="obj"></param>
        void SCUFTotemCreate(object obj)
        {
            netBattle.TotemRefresh((SCUFTotemCreate)obj);
            Debug.Log("<color=purple>[union fight]recv SCUFTotemCreate</color>");
        }

        /// <summary>
        /// 图腾销毁
        /// </summary>
        /// <param name="obj"></param>
        void SCUFTotemDestroy(object obj)
        {
            netBattle.TotomDestroy((SCUFTotemDestroy)obj);
            Debug.Log("<color=purple>[union fight]recv SCUFTotemCreate</color>");
        }


        /// <summary>
        /// 主角改变速度
        /// </summary>
        /// <param name="obj"></param>
        void SCUFMainPlayerSpeedChange(object obj)
        {
            netActor.ActorSpeed((SCUFMainPlayerSpeedChange)obj);
            Debug.Log("<color=purple>[union fight]recv SCUFMainPlayerSpeedChange</color>");
        }

        /// <summary>
        /// 个人任务   公会任务    红点
        /// </summary>
        /// <param name="obj"></param>
        void SCUFPlayerMissionList(object obj)
        {
            netBattle.PlayerMissionList((SCUFPlayerMissionList)obj);
            Debug.Log("<color=purple>[union fight]recv SCUFPlayerMissionList</color>");
        }

        void SCUFUnionMissionList(object obj)
        {
            netBattle.UnionMissionList((SCUFUnionMissionList)obj);
            Debug.Log("<color=purple>[union fight]recv SCUFUnionMissionList</color>");
        }
        //红点推送
        void SCUFMissionPush(object obj)
        {
            netBattle.MissionPush((SCUFMissionPush)obj);
            Debug.Log("<color=purple>[union fight]recv SCUFMissionPush</color>");
        }

        //战斗记录
        void SCUFFightRecord(object obj)
        {
            netBattle.FightRecord((SCUFFightRecord)obj);
            Debug.Log("<color=purple>[union fight]recv SCUFFightRecord</color>");
        }

        void SCUFFightRecordReplay(object obj)
        {
            netBattle.FightRecordReplay((SCUFFightRecordReplay)obj);
            Debug.Log("<color=purple>[union fight]recv SCUFFightRecordReplay</color>");
        }

        //会长集结点
        void SCUFLeaderFocus(object obj)
        {
            netBattle.LeaderFocus((SCUFLeaderFocus)obj);
            Debug.Log("<color=purple>[union fight]recv SCUFLeaderFocus</color>");
        }

        //玩家集结点
        void SCUFFocusPointInfo(object obj)
        {
            netBattle.LeaderFocusDisappear((SCUFFocusPointInfo)obj);
            Debug.Log("<color=purple>[union fight]recv SCUFFocusPointInfo</color>");
        }
        
        //连杀特效
        void SCUFPlayerCcmpleteAchieve(object obj)
        {
            netActor.PlayerCcmpleteAchieve((SCUFPlayerCcmpleteAchieve)obj);
            Debug.Log("<color=purple>[union fight]recv SCUFPlayerCcmpleteAchieve</color>");
        }
        void SCUFOnHook(object obj)
        {
            netBattle.HookOn((SCUFOnHook)obj);
            Debug.Log("<color=purple>[union fight]recv SCUFOnHook "+ ((SCUFOnHook)obj).onHook + "</color>");
        }

        void SCUFBeginTransfer(object obj)
        {
            netActor.ActorTransferBegin((SCUFBeginTransfer)obj);
            Debug.Log("<color=purple>[union fight]recv SCUFBeginTransfer</color>");
        }

        void SCUFEndTransfer(object obj)
        {
            netActor.ActorTransferEnd((SCUFEndTransfer)obj);
            Debug.Log("<color=purple>[union fight]recv SCUFEndTransfer</color>");
        }

        /// <summary>
        /// 强制踢回主城
        /// </summary>
        /// <param name="obj"></param>
        void SCUFKickPlayer(object obj)
        {
            netBattle.KickBack((SCUFKickPlayer)obj);
            Debug.Log("<color=purple>[union fight]recv SCUFKickPlayer</color>");
        }

        /// <summary>
        /// 刷新工厂
        /// </summary>
        /// <param name="obj"></param>
        void SCUFCariotFactory(object obj)
        {
            var msg = (SCUFCariotFactory)obj;
            netChariotFactory.ChariotFactoryRefresh(msg.factory);
            Debug.Log("<color=purple>[union fight]recv SCUFCariotFactory</color>");
        }

        /// <summary>
        /// 刷塔的状态
        /// </summary>
        /// <param name="obj"></param>
        void SCUFTowerRecovery(object obj)
        {
            var msg = (SCUFTowerRecovery)obj;
            netTower.TowerRefresh(msg.tower);
            Debug.Log("<color=purple>[union fight]recv SCUFTowerRecovery</color>");
        }

        //公会喊话
        void SCUFTalk(object obj)
        {
            var msg = (SCUFTalk)obj;
            netBattle.UFTalk(msg);
            Debug.Log("<color=purple>[union fight]recv SCUFTalk</color>");
        }

        public override void SCPublicMessage(object obj)
        {
            var msg = (SCPublicMessage)obj;
            netBattle.ReceiveMsg(msg);
            Debug.Log("<color=purple>[union fight]recv SCPublicMessage</color>");
        }
        #endregion

        #region Solve



        public void SolveCommonMove(SCUFElementMove msg)
        {
#if UNITY_EDITOR
            ((RoomUnionFight)roomBase).moveMsg = msg;
#endif
            for (int i =0;i<msg.guid.Count;++i)
            {
                var uuid = msg.guid[i] ;
                var pos = msg.pos[i];

                var speed = msg.speed[i];

                var charactor = charactorManager.GetCharactor(uuid+"");
                if(charactor==null)
                {
                    SendCSUFRefreshElement(uuid);
                    continue;
                }
                else
                {
                    if(charactor.type == CharactorType.UnionFightOther 
                        ||charactor.type == CharactorType.UnionFightSelf)
                    {
                        SendCSMoveConfirm();
                    }
                }

                if(uuid == StaticData.playerData.playerId)
                {
                    if (UnionFightData.IsOnHook)
                    {
                        var spos = new Vector3(pos.x, pos.y, pos.z);

                        var mv = new InnerMover();
                        mv.uuid = uuid;
                        mv.nextPos = spos;
                        mv.state = (int)UnionActorState.Move;

                        if (!RCMoveNavigation.SamplePosition(spos, out spos))
                        {
                            Debug.LogError("[DEBUG] can't go " + spos);
                            continue;
                        }
#if UNITY_EDITOR
                        var obj = GameObject.CreatePrimitive(PrimitiveType.Sphere);
                        obj.transform.position = spos;
                        GameObject.Destroy(obj, 5f);
#endif
                        var dis = Vector3.Distance(spos, charactor.transform.position);
                        if (dis < 2)
                            charactor.SetSpeed(speed * 1.05f);
                        else if (dis > 5)
                            charactor.SetSpeed(speed * 2f);
                        else
                            charactor.SetSpeed(speed * 1.5f);


                        mainActorSpeed = speed;
                        moveQueue.Enqueue(mv);
                    }
                    else
                    {
                        var spos = new Vector3(pos.x, pos.y, pos.z);
                        netActor.UpdatePosition(uuid, spos);
                    }
                    continue;
                }
                

                var pos0 = new Vector2(pos.x, pos.z);
                var pos1 = new Vector2(charactor.transform.position.x, charactor.transform.position.z);
                var dis0 = Vector2.Distance(pos0, pos1);
                if (dis0 > forceSyncDis)
                {
                    netActor.UpdatePosition(uuid, new Vector3(pos.x,pos.y,pos.z));
                    continue;
                }

                var mover = new InnerMover(uuid, pos);

                if (!RCMoveNavigation.SamplePosition(mover.nextPos, out mover.nextPos))
                {
                    Debug.LogError("[DEBUG] can't go " + mover.nextPos);
                    continue;
                }

                if (NetUnionFightBase.postions.ContainsKey(uuid))
                {
                    var oldPos = NetUnionFightBase.postions[uuid];
                    if(oldPos == mover.nextPos)
                    {
                        Debug.LogWarning("[REEOR] recv same pos info ");
                        continue;
                    }
                }

                var discard = false;
                switch (charactor.type)
                {
                    case CharactorType.UnionFightOther:
                    case CharactorType.UnionFightSelf:
                        var ai = charactor.ai as RCAIUnionActor;
                        if (!ai.IdleState())
                        {
                            discard = true;
                            netActor.UpdatePosition(uuid, mover.nextPos);   
                        }
                        else
                        {
                            NetUnionFightBase.postions[uuid] = mover.nextPos;
                            netActor.UpdateState(uuid, (int)UnionActorState.Move);
                        }
                        break;
                    case CharactorType.UnionFightChariot:
                        NetUnionFightBase.postions[uuid] = mover.nextPos;
                        netChariot.UpdateState(uuid, (int)UnionChariotState.Move);
                        break;
                    case CharactorType.UnionFightGuard:
                         var guardAi = charactor.ai as RCAIGuard;
                        if (guardAi.CurrState == UnionGuardState.Attack)
                        {
                            discard = true;
                            netGuard.UpdatePosition(uuid, mover.nextPos);
                        }
                        else
                        {
                            NetUnionFightBase.postions[uuid] = mover.nextPos;
                            netGuard.UpdateState(uuid, (int)UnionGuardState.Move);
                        }
                        break;
                    case CharactorType.UnionFightMonster:
                        NetUnionFightBase.postions[uuid] = mover.nextPos;
                        netMonster.UpdateState(uuid, (int)UnionMonsterState.Move);
                        break;
                }

                if(discard)
                {
                    continue;
                }

                moveQueue.Enqueue(mover);
                charactor.SetSpeed(speed);
            }
        }

        private void SolveMoveActor(InnerMover mover)
        {
            var charactor = charactorManager.GetCharactor(mover.uuid+"");
            if (charactor != null)
            {
                charactor.StopTo(mover.nextPos);
            }
        }

        private void SolveSyncSelfToServer()
        {
            if (UnionFightData.IsOnHook)
                return;
            var self = roomBase.charactorManager.GetSelfCharactor();

            if (self == null)
                return;
            if (Time.time - lastCommitTime < sendTime)
                return;

            lastCommitTime = Time.time;

            var pos = self.transform.position;

            if (lastPosition == pos)
                return;

            lastPosition = pos;

            var msg = new CSMove();
            var p = new PointNew();
            p.x = pos.x;
            p.y = pos.y;
            p.z = pos.z;

            msg.pointNew = p;

            NetAPI.SendSocket(OpDefine.CSMove, msg);
            Debug.Log("<color=blue>[send] CSMove </color>");
        }

        private void SolveCheckMainPlayerState()
        {

        }

        #endregion

        public void OnCharactorDestroy(string uuid)
        {
            var longUuid = 0L;
            if (long.TryParse(uuid, out longUuid))
            {
                foreach (var inner in netAction)
                {
                    inner.ClearCharactorData(longUuid);
                }
            }
        }
    }
}